<template>
  <section>
    <el-button
      v-permission="installPermissions.permissions.member.edit"
      @click="handleEdit(row)"
      type="text"
      size="small"
    >
      编辑
    </el-button>
    <el-button
      v-permission="installPermissions.permissions.member.del"
      @click="handleDelete(row)"
      type="text"
      size="small"
    >
      删除
    </el-button>
  </section>
</template>
<style>
</style>
<script>
    export default {
        props: {
            row: {
                type: Object,
                default: function () {
                    return {};
                }
            },
            col: {
                type: Object,
                default: function () {
                    return {};
                }
            }
        },
        methods: {
            // hanldCommand(cmd) {
            //   switch (cmd) {
            //     case "edit":
            //       return this.handleEdit();
            //     case "delete":
            //       return this.handleDelete();
            //     case "role":
            //       return this.$emit("roleShow", this.row);
            //     case "permission":
            //       return this.$emit("permissionShow", this.row);
            //     case "reset":
            //         return this.handleReset();
            //     default:
            //       return this.handleStatus();
            //   }
            // },
            handleStatus() {
                let ops = this.row.status.value == "EFFECTIVED" ? "禁用" : "激活";
                let status =
                    this.row.status.value == "EFFECTIVED" ? "INVALID" : "EFFECTIVED";
                this.$confirm("此操作将" + ops + "该用户, 是否继续?", ops + "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(() => {
                    this.$api.user.status(this.row.id, status, () => {
                        this.$message({
                            type: "success",
                            message: ops + "用户成功",
                            onClose: this.$emit("deleteDone", this.row)
                        });
                    });
                });
            },
            handleDelete() {
                this.$confirm("此操作将删除该用户, 是否继续?", "删除提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(() => {
                    this.$api.member.delete(this.row.id, () => {
                        this.$message({
                            type: "success",
                            message: "删除用户成功",
                            onClose: () => {
                                this.$emit("deleteDone", this.row);
                            }
                        });
                    });
                });
            },
            // handleReset() {
            //     this.$confirm("此操作将重置该用户密码, 是否继续?", "重置密码提示", {
            //         confirmButtonText: "确定",
            //         cancelButtonText: "取消",
            //         type: "warning"
            //     }).then(() => {
            //         this.$api.user.reset(this.row.id, () => {
            //             this.$message({
            //                 type: "success",
            //                 message: "重置密码成功",
            //                 onClose: () => {
            //                     this.$emit("deleteDone", this.row);
            //                 }
            //             });
            //         });
            //     });
            // },
            handleEdit() {
                this.$emit("editRow", this.row);
            },
            handleGrant() {
                this.$emit("grantShow", this.row);
            }
        }
    };
</script>
